package cn.zorbus.laian.application.service;

import cn.zorbus.laian.domain.repository.IVideoRepository;
import cn.zorbus.laian.infrastructure.common.command.VideoChangeCommand;
import cn.zorbus.laian.infrastructure.common.command.VideoStatusCommand;
import cn.zorbus.laian.infrastructure.common.view.VideoView;
import cn.zorbus.laian.infrastructure.config.VideoProperties;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.Collection;

/**
 * create in 2023/12/1 19:56
 *
 * @author shishaodong
 * @version 0.0.1
 */
@Slf4j
@Service
@Validated
@RequiredArgsConstructor
public class VideoService {

//    private static final String path = "E:项目\\2-南京宜本文化\\视频播放客户端\\YB-MediaPlay\\YB-MediaPlay\\bin\\Debug\\Media\\";

    private final IVideoRepository repository;

    private final VideoProperties videoProperties;



    public Collection<VideoView> findAll() {
        Collection<VideoView> allVideos = repository.findAllVideos();
        return allVideos.stream().filter(x->! StringUtils.contains(x.getFilename(),"SCREENSHOT")).toList();
    }

    public VideoView current() {
        VideoView current = repository.findCurrent();
        String replace = videoProperties.getPath();
//        String replace = videoProperties.getPath().replace("\\", "/");
        return VideoView.builder()
                .videoPath(replace + current.getFilename())
                .filename(current.getFilename())
                .status(current.getStatus())
                .build();
    }

    public VideoView videoImage(String id) {
        return repository.findById(id);
    }

    public void videoChange(@Valid VideoChangeCommand command) {
        int change = repository.videoChange(command);
        log.info("{}|{}", command, change);
    }


    public void videoStatus(@Valid VideoStatusCommand command) {
        int status = repository.videoStatus(command);
        log.info("{}|{}", command, status);
    }
}
